#!/usr/bin/perl -w
package node::filesystem_space;

use Config;
use Filesys::DfPortable;

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self  = {};
my $name=shift;
my $value=shift;	# We expect the value to the mount_point

	if($Config{osname} ne "hpux" && $Config{osname} ne "linux") {
		::warnmsg("Currently only works on HP-UX/Linux!") if defined(&::warnmsg);
		return undef;
	}
	if(!defined($value) || !length($value)) {
		::warnmsg("No file system name provided as a value to monitor.") if defined(&::warnmsg);
		return undef;
	}
	$self->{name}=$name;
	$self->{value}=$value;
	$self->{min_interval}=10;
	$self->{description}="File system space monitor";
	bless ($self, $class);
	return($self);
}

sub action_args {
my $self=shift;

	return "threshold";

}

sub min_interval {
my $self=shift;

	return $self->{min_interval};
}

#################################################################
# Since action_args is "threshold" we return a % value - i.e.	#
# a number between 0 and 100 inclusive.				#
#################################################################

sub test {
my $self=shift;

	my $m=$self->{value};
	my $r=dfportable($m,1024);
	if(!defined($r)) {
		::warnmsg("Unable to get file system info for '$m'.") if defined(&::warnmsg);
		return(0);
	}
	return int($r->{per});
}

sub reset {
my $self=shift;

}

sub desc {
my $self=shift;

	return $self->{description};
}

1;

